Trait (computer programming)

In computer programming, a trait is a collection of methods, used as a "simple conceptual model for structuring object oriented programs".[1] [2] [3] Traits are similar to mixins, but whereas mixins can be composed only using the inheritance operation, traits offer a much wider selection of operations, including symmetric sum, method exclusion, and aliasing. A Trait differs from an abstract type in that it provides implementations of its methods, not just type signatures.

Traits come from the Self programming language and are supported as a native language feature in the Fortress programming language (where they also play the role of types), in the Scala programming language,[4][5] the Pharo version of Squeak Smalltalk, as "categories" in the Objective-C language, and in Perl 6 (which calls them "roles"), as an add-on by the Moose module for Perl 5 and the Joose framework for JavaScript and will be included in PHP 5.4[6]. Abstract classes as mixins in the multiple-inheritance Curl programming language permit method implementations and thus constituted traits by another name. Module mixins in Ruby are similar to traits to some degree. Racket supports traits as a library and uses macros, structures, and first-class classes to implement them.

Traits for the Smalltalk programming language were initially developed at the Software Composition Group, University of Bern.[7]

References

  1. ^ http://web.cecs.pdx.edu/~black/publications/TR_CSE_02-012.pdf
  2. ^ Nathanael Schärli, Stéphane Ducasse, Oscar Nierstrasz, Andrew P. Black. Traits: Composable Units of Behaviour. Proceedings of the European Conference on Object-Oriented Programming (ECOOP). Lecture Notes in Computer Science, Volume 2743, Springer-Verlag, 2003, pp. 248-274
  3. ^ Stéphane Ducasse, Oscar Nierstrasz, Nathanael Schärli, Roel Wuyts, Andrew P. Black: Traits: A mechanism for fine-grained reuse. ACM Trans. Program. Lang. Syst. 28(2): 331-388 (2006)
  4. ^ http://www.scala-lang.org/node/126 A Tour of Scala: Traits
  5. ^ http://www.ibm.com/developerworks/java/library/j-scala04298.html The busy Java developer's guide to Scala: Of traits and behaviors
  6. ^ Marr, Stefan. "Request for Comments: Horizontal Reuse for PHP". The PHP.net wiki. The PHP Group. https://wiki.php.net/rfc/horizontalreuse. Retrieved 31 January 2011. 
  7. ^ http://scg.unibe.ch/cgi-bin/scgbib.cgi?query=nathanael+traits+composable+units+ecoop

External links